<template>
	<view>
		<u-tabs :list="list" inactive-color="#808080" active-color="#000" :current="current"
		@change="change" duration="0.3"></u-tabs>
		<view style="padding: 20rpx;" v-if="current == 0">
			<view v-for="(item,index) in commentUser" :key="index" style="margin: 10rpx 0 50rpx 0;">
				<view style="margin: 20rpx 0;"class="u-flex">
					<u-avatar :src="$url+item.avatar"></u-avatar>
					<view style="margin-left: 20rpx;">
						
						<view>{{item.userName}}</view>
						<view style="color: #B2B2B4;">{{item.commentTime | formatDate}}</view>
					</view>
				</view>
				<view style="font-size: 32rpx;">
					<view>{{item.content}}</view>
				</view>
				<view style="margin: 10rpx;background-color: #f7f7f7;border-radius: 0.5em;padding: 30rpx;
				justify-content: space-between;"
				class="u-flex" @click="itemClick(item.bookdataId)">
					<image :src="$url+item.imageUrl" mode="aspectFill"
					style="width: 80rpx;height: 120rpx;"></image>
					<view style="flex: 1;margin: 0 20rpx;">
						<view>{{item.name}}</view>
						<view style="color: #808080;">{{item.types}}&nbsp;·&nbsp;{{item.state}}&nbsp;·&nbsp;{{item.heat}}万热度</view>
					</view>
					<view style="color: #e76f3b;">{{item.score}}分</view>
				</view>
			</view>
		</view>
		<view style="padding: 20rpx;" v-if="current == 1">
			<u-card v-for="(item,index) in feedbacks" :key="index" boxShadow="0 0 10rpx 5rpx #F8F8F8">
				<view slot="head" class="u-flex" style="justify-content: space-between;">
					<view>{{item.title}}</view>
					<view style="border: #007AFF 1rpx solid;color: #007AFF;padding: 10rpx;">{{item.state == 0?'待处理中':'已处理'}}</view>
				</view>
				<view slot="body">
					<view style="padding: 10rpx;">
						<text style="color: #999999;margin-right: 20rpx;">反馈内容</text>
						<text>{{item.content}}</text>
					</view>
					<view style="padding: 10rpx;">
						<text style="color: #999999;margin-right: 20rpx;">反馈时间</text>
						<text>{{item.feedbackTime | formatDate}}</text>
					</view>
				</view>
			</u-card>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				current:0,
				list:[
					{id:1,name:"我发布消息"},
					{id:2,name:"我提交的反馈"}
				],
				commentUser:[],
				feedbacks:[]
			}
		},
		methods: {
			//
			async getCommentUser(){
				const res=await this.$myRequst({
					url:"/comment/gets/userId/"+uni.getStorageSync("userId")
				})
				console.log(res.data.data)
				this.commentUser = res.data.data
			},
			itemClick(e){
				uni.navigateTo({
					url:"../../index/bookItem/bookItem?id="+e
				})
			},
			change(e){
				this.current = e
			},
			//
			async getFeedbacks(){
				const res=await this.$myRequst({
					url:"/feedback/gets/"+uni.getStorageSync("userId")
				})
				this.feedbacks = res.data.data
				console.log(this.feedbacks)	
			}
		},
		filters: {
		  numFilter (value) {
		    // 截取当前数据到小数点后两位
		    let realVal = parseFloat(value).toFixed(2)
		    return realVal
		  },
		  formatDate(value) {
		  	if(value == undefined){
		  		return;
		  	}
		  	// let date = new Date(value * 1000);
		  	let date = new Date(value);
		  	//时间戳为10位需*1000，时间戳为13位的话不需乘1000
		  	let y = date.getFullYear();
		  	let MM = date.getMonth() + 1;
		  	MM = MM < 10 ? ('0' + MM) : MM; //月补0
		  	let d = date.getDate();
		  	d = d < 10 ? ('0' + d) : d; //天补0
		  	let h = date.getHours();
		  	h = h < 10 ? ('0' + h) : h; //小时补0
		  	let m = date.getMinutes();
		  	m = m < 10 ? ('0' + m) : m; //分钟补0
		  	let s = date.getSeconds();
		  	s = s < 10 ? ('0' + s) : s; //秒补0
		  	// return y + '-' + MM + '-' + d; //年月日
		  	return y + '-' + MM + '-' + d + ' ' + h + ':' + m+ ':' + s; //年月日时分秒
		  }
		},
		onLoad() {
			this.getCommentUser()
			this.getFeedbacks()
		}
	}
</script>

<style>

</style>
